package org.dashboard.security;

import org.dashboard.constant.Constant;
import org.dashboard.utils.XXTEABase64Util;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.Objects;

/**
 * Copyright © 2018. All rights reserved.
 *
 * @Author: FreezeSoul
 * @CreateDate: 2018/4/13 10:32
 * @Description:
 * @Version: V1.0
 */
public class FlasherPasswordEncoder implements PasswordEncoder {

    @Value("${jwt.secret}")
    private String tokenSecret;

    @Override
    public String encode(CharSequence rawPassword) {
        return XXTEABase64Util.encryptToBase64String(rawPassword.toString(), tokenSecret);

    }

    /**
     * defaultPassword: admin:
     * @param rawPassword
     * @param encodedPassword
     * @return
     */
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return Objects.equals(XXTEABase64Util.encryptToBase64String(rawPassword.toString(), tokenSecret), encodedPassword);
    }

}